
Date.prototype.format = function(fmt) { 
    if(isNaN(this.getFullYear()))
    {
        return "";
    }
    
   var o = { 
      "M+" : this.getUTCMonth()+1,                 //月份 
      "d+" : this.getUTCDate(),                    //日 
      "h+" : this.getUTCHours(),                   //小时 
      "m+" : this.getUTCMinutes(),                 //分 
      "s+" : this.getUTCSeconds(),                 //秒 
      "q+" : Math.floor((this.getMonth()+3)/3), //季度 
      "S"  : this.getUTCMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) {
          fmt=fmt.replace(RegExp.$1, (this.getUTCFullYear()+"").substr(4 - RegExp.$1.length)); 
  }
   for(var k in o) {
      if(new RegExp("("+ k +")").test(fmt)){
           fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
       }
   }
  return fmt; 
}  
Date.prototype.formatLocal = function(fmt) { 
    if(isNaN(this.getFullYear()))
    {
        return "";
    }
    
   var o = { 
      "M+" : this.getMonth()+1,                 //月份 
      "d+" : this.getDate(),                    //日 
      "h+" : this.getHours(),                   //小时 
      "m+" : this.getMinutes(),                 //分 
      "s+" : this.getSeconds(),                 //秒 
      "q+" : Math.floor((this.getMonth()+3)/3), //季度 
      "S"  : this.getMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) {
          fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
  }
   for(var k in o) {
      if(new RegExp("("+ k +")").test(fmt)){
           fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
       }
   }
  return fmt; 
}  
String.prototype.repeat = String.prototype.repeat || function(num) {
    return new Array(num + 1).join(this);
};

$test={
	aaa:3,
	testfun:function(el){
		alert(document);alert(el);}
	}

$jm=
{
	zeroize:function (vv,len)
	{
		var sv=new String(vv);
		var sn=sv.length;
		if(sn>=len)
		{
			return sv;//.substring(sn-len,sn);
		}else
		{
			var zero="0";
			return zero.repeat(len-sn)+sv;			
		}
	},
	GetDayOfYear:function(d)
	{
		var d2 = new Date(d.getFullYear(), 0, 1);
		return Math.floor( (((d - d2) / 86400000)+d2.getDay()) / 7)+1;
	},
	date_format:function(sfmt,d)
	{
		fmt=new String(sfmt);
		return fmt.replace(/(y{1,4})|(M{1,2})|(d{1,2})|(H{1,2})|(m{1,2})|(s{1,2})|([w]{1})|(D{1,2})|(W{1,2})|(S{1,2})/g,
			function(str){
				switch(str)
				{
				case 'y':return String(d.getFullYear()).substr(2);
				case 'yy':return String(d.getFullYear()).substr(2);
				case 'yyy':return String(d.getFullYear()).substr(3);
				case 'yyyy':return String(d.getFullYear());
				case 'M':return d.getMonth() + 1;
				case 'MM': return $jm.zeroize(d.getMonth() + 1,2);
				case 'MMM': return ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][d.getMonth()];
				case 'MMMM':return ['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];
				case 'd':   return d.getDate();
				case 'dd': return $jm.zeroize(d.getDate(),2);
				case 'H':   return d.getHours();
				case 'HH':return $jm.zeroize(d.getHours(),2);
				case 'm':   return d.getMinutes();
				case 'mm': return $jm.zeroize(d.getMinutes(),2);
				case 's':   return d.getSeconds(); 
				case 'ss':  return $jm.zeroize(d.getSeconds(),2);
				case 'D': return ['日','一','二','三','四','五','六'][d.getDay()];
				case 'DD':return ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'][d.getDay()];
				case 'w': return ['0','1','2','3','4','5','6'][d.getDay()];
				case 'W':return $jm.GetDayOfYear(d);
				case 'WW': return $jm.zeroize($jm.GetDayOfYear(d),2);
				case 'S': return d.getMilliseconds();
				case 'SS': return $jm.zeroize(d.getMilliseconds(),3);
				};
				return "";
			});		
	},
	date_parse:function(dts)
	{
		//var ds=new String("2019-06-20T18:08:00.000") ;
		ds=new String(dts);
		var dt=new Date();
		var pat4=/^[\s]*(\d{4})/ 
		var pat3=/^[\.\:\s\,](\d{3})/ ;
		var pat2=/^[\-\:T\s](\d{2})/ 
		var mch= ds.match(pat4);
		if(mch==null)
		{
			return dt;
		}
	
		dt.setFullYear(parseInt(mch[1],10),0,1);
		
		ds=ds.substring(mch.index+mch[0].length,ds.length);
		mch=ds.match(pat2);
		if(mch==null)
		{
			dt.setHours(0,0,0,0);
			return dt;
		}
	
		dt.setMonth(parseInt(mch[1],10)-1,1);
		
		ds=ds.substring(mch.index+mch[0].length,ds.length);
		mch=ds.match(pat2);
		if(mch==null)
		{
			dt.setHours(0,0,0,0);
			return dt;
		}
		dt.setDate(parseInt(mch[1],10));
		
		
		ds=ds.substring(mch.index+mch[0].length,ds.length);
		mch=ds.match(pat2);
		if(mch==null)
		{
			dt.setHours(0,0,0,0);
			return dt;
		}
		dt.setHours(parseInt(mch[1],10),0,0,0);
		
		ds=ds.substring(mch.index+mch[0].length,ds.length);
		mch=ds.match(pat2);
		if(mch==null)
		{
			return dt;
		}
		dt.setMinutes(parseInt(mch[1],10),0,0);
		
		ds=ds.substring(mch.index+mch[0].length,ds.length);
		mch=ds.match(pat2);
		if(mch==null)
		{
			return dt;
		}
		dt.setSeconds(parseInt(mch[1],10),0);
		
		ds=ds.substring(mch.index+mch[0].length,ds.length);
		mch=ds.match(pat3);
		if(mch==null)
		{
			return dt;
		}
		dt.setMilliseconds(parseInt(mch[1],10));
		return dt;
	},
	textareaAutoHeight:function (txte)
	{//oninput="textareaAutoHeight(this)" style=" width:100%; text-indent:4em; resize:none; border-width:0px"
		txte.style.height = 'auto';
		txte.style.height = (txte.scrollHeight) + 'px';
	},
	HTMLDecode:function(input) 
	{ 
		var converter = document.createElement("div"); 
		converter. innerHTML = input; 
		var output = converter. innerText; 
		converter = null; 
		return output; 
	} ,
	HTMLEncode:function(input) 
	{ 
		var converter = document.createElement("div"); 
		converter. innerText = input; 
		var output = converter. innerHTML; 
		converter = null; 
		return output; 
	},
	insertAfter:function (newElement, targetElement){
		var parent = targetElement.parentNode;
		if (parent.lastChild == targetElement) {
			parent.appendChild(newElement);
		}
		else {
			parent.insertBefore(newElement, targetElement.nextSibling);
		}
	},
	removeElement:function (_element){
		var _parentElement = _element.parentNode;
		if(_parentElement){
			_parentElement.removeChild(_element);  
		}
	} ,
	popup_option_KTV:function (el,select_options)
	{
	
		var pos={x:el.offsetLeft,y:el.offsetTop};
		for(var parent=el.offsetParent;parent;parent=parent.offsetParent)
		{
			pos.x+=parent.offsetLeft;
			pos.y+=parent.offsetTop;
		}			
		pos.y+=el.offsetHeight;
		
		
		var new_wnd=document.createElement("div");
		new_wnd.style.cssText="padding:0px;position:absolute;border-width:thin; border-style:solid; border-color:#6FF;display:none;z-index:50;background-color:#FFF;";
		new_wnd.tabIndex="-1";
		var onSelectedItem=el.getAttribute("onSelectedItem");
		var onSelectedItemFun=null;
		if(onSelectedItem)
		{
			if(typeof(onSelectedItem)=="string")
			{
				onSelectedItemFun=function(item)
				{
					return eval(onSelectedItem);
				};
			}else if(typeof(onSelectedItem)=="function")
			{
				onSelectedItemFun=onSelectedItem;
			}else
			{
				onSelectedItemFun=function(item)
				{};
			}
		}else{
			onSelectedItemFun=function(item)
			{};
		}
		var idx=0;
		for(var i=0;i<select_options.length;++i)
		{
			if(select_options[i].T=='<hr/>')
			{
				new_wnd.appendChild(document.createElement("hr"));
				continue;
			}
			var new_item=document.createElement("div");
			new_item.style.cssText="background-color:#FFF;padding:0px 1em 0px 1em";			
			new_item.itemIndex=idx++;
			new_item.innerHTML=select_options[i].T;
			new_item.itemText=new_item.innerText;
			new_item.itemKey=select_options[i].K;
			new_item.itemValue=select_options[i].V;
			new_item.onmouseover=(function(nitem){
					return function(){
						nitem.style.backgroundColor="#00F";
						nitem.style.color="#FFF";
					};
				})(new_item);
			new_item.onmouseout=(function(nitem){
					return function(){
						nitem.style.backgroundColor="#FFF";
						nitem.style.color="#000";
					};
				})(new_item);
			
			new_item.onclick=(function(eThis,eItem,selectedItemFun)
			{
				return function(){
					new_wnd.style.display="none";
					selectedItemFun.call(eThis,eItem);
					document.body.removeChild(new_wnd);
				};
			})(el,new_item,onSelectedItemFun);
			new_wnd.appendChild(new_item);
		}
		new_wnd.style.left=pos.x+"px";
		new_wnd.style.top=pos.y+"px";
		new_wnd.onblur=function(){
			new_wnd.style.display="none";
			document.body.removeChild(new_wnd);
		};
		document.body.appendChild(new_wnd);
		new_wnd.style.display="block";
		new_wnd.focus();
	},
	popup_option:function (el,select_options)
	{
		if(typeof(el)=="string")
		{
			el=document.getElementById(el);
		}
		if(el)
		{
			$jm.popup_option_KTV(el,select_options);
		}
	},
	set_focus:function(el)
	{
		if(typeof(el)=="string")
		{
			el=document.getElementById(el);
		}
		if(el)
		{
			el.focus();
		}
	},
	popup_option_eg:function (el)
	{
		var select_options=[{K:'itemKey',T:'<h1>itemText</h1>',V:'itemValue'},
							{T:'<hr/>'},
							{K:'key1',T:'text1',V:'value1'},
							{K:'key2',T:'text2',V:'value2'}];
		$jm.popup_option(el,select_options);
	},
	popup_option_sex:function(el)
	{
		var select_options=[{T:'(清空)',V:''},{T:'男',V:'男'},{T:'女',V:'女'},{T:'不详',V:'不详'}];
		$jm.popup_option(el,select_options);
	}
};


$bl={
	fromTagDBK:function(tag,dbk)
	{
		var retputs=[];
		var inputs=document.getElementsByTagName(tag);
		for(var i=0;i<inputs.length;++i)
		{
			var attr=inputs[i].getAttribute("dbkey");

			if(attr && attr==dbk)
			{
				retputs.push(inputs[i]);
			}
		}
		return retputs;
	},
	setInputValueOnDbkey:function (dbk,value)
	{
		var inputs=$bl.fromTagDBK("input",dbk);
		for(var i=0;i<inputs.length;++i)
		{
			inputs[i].value=value;
		}
	},
	setTextOnDbkey:function(dbk,text)
	{
		var inputs=$bl.fromTagDBK("input",dbk);
		for(var i=0;i<inputs.length;++i)
		{
			inputs[i].value=text;
		}
		inputs=$bl.fromTagDBK("textarea",dbk);
		for(var i=0;i<inputs.length;++i)
		{
			inputs[i].value=text;
		}
		inputs=$bl.fromTagDBK("div",dbk);
		for(var i=0;i<inputs.length;++i)
		{
			inputs[i].innerText=text;
		}
		inputs=$bl.fromTagDBK("span",dbk);
		for(var i=0;i<inputs.length;++i)
		{
			inputs[i].innerText=text;
		}
		inputs=$bl.fromTagDBK("td",dbk);
		for(var i=0;i<inputs.length;++i)
		{
			inputs[i].innerText=text;
		}
	},
	setupTextOnDbkey:function(tb)
	{
		var inputs=document.getElementsByTagName("input");
		for(var i=0;i<inputs.length;++i)
		{
			var dbk=inputs[i].getAttribute("dbkey");
			if(dbk && tb.hasOwnProperty(dbk))
			{
				inputs[i].value=tb[dbk];
				
			}
		}
		inputs=document.getElementsByTagName("textarea");
		for(var i=0;i<inputs.length;++i)
		{
			var dbk=inputs[i].getAttribute("dbkey");
			if(dbk && tb.hasOwnProperty(dbk))
			{
				inputs[i].value=tb[dbk];
				$jm.textareaAutoHeight(inputs[i]);
			}
		}
		inputs=document.getElementsByTagName("div");
		for(var i=0;i<inputs.length;++i)
		{
			var dbk=inputs[i].getAttribute("dbkey");
			if(dbk && tb.hasOwnProperty(dbk))
			{
				inputs[i].innerText=tb[dbk];
			}
		}
		inputs=document.getElementsByTagName("span");
		for(var i=0;i<inputs.length;++i)
		{
			var dbk=inputs[i].getAttribute("dbkey");
			if(dbk && tb.hasOwnProperty(dbk))
			{
				inputs[i].innerText=tb[dbk];
			}
		}
		inputs=document.getElementsByTagName("td");
		for(var i=0;i<inputs.length;++i)
		{
			var dbk=inputs[i].getAttribute("dbkey");
			if(dbk && tb.hasOwnProperty(dbk))
			{
				inputs[i].innerText=tb[dbk];
			}
		}
	},
	add_new_bcjl:function(btn,gethtmlfun)
	{
		//var btn=document.getElementById("newitem_bcjl");
		//alert(btn);
		var jlnm=new String(btn.id);
		jlnm=jlnm.substring(8);
		var bcjl_count_id=jlnm+"_count";
		var idx=new String(parseInt(document.getElementById(bcjl_count_id).value)+1);
		document.getElementById(bcjl_count_id).value=idx;
		var new_html=gethtmlfun(idx);
		var new_div=document.createElement("div");
		new_div.innerHTML=new_html;
		btn.parentNode.insertBefore(new_div.firstElementChild,btn);
		var bcrq_id=jlnm+"F_BCRQ_"+idx;
		var bcrq_el=document.getElementById(bcrq_id);
		var date_fmt=bcrq_el.getAttribute("dateFmt");
		var now_dt= jeDate.timeStampDate(Math.floor(Date.now()/1000),date_fmt); 
		bcrq_el.setAttribute("value",now_dt);
		
		jeDate(bcrq_el,{
			festival:true,
			//minDate:"1900-01-01",              //最小日期
			//maxDate:"2099-12-31",              //最大日期
			//method:{
			//	choose:function (params) {					
			//	}
			//},
			theme:{bgcolor:"#D91600",pnColor:"#FF6653"},
			format: date_fmt
		});      
	},
}



function parse_template()
{
	var els=document.getElementsByClassName("ip_field ta_field sp_field");
	var dats=new Map();
	for(var idx in els)
	{
		
		if(els[idx].tagName=="span")
		{
			var str=eval("`"+els[idx].innerText+"`");
			
		}else
		{
		}
	}
}









